home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / languages / pcq_incl3v1.lha / DOS / RDArgs.i < prev    next >
Encoding:
Text File  |  1994-04-15  |  4.7 KB  |  122 lines

  1.  
  2. {$I   "Include:Exec/Nodes.i"}
  3.  
  4. {   *********************************************************************
  5.  *
  6.  * The CSource data structure defines the input source for "ReadItem()"
  7.  * as well as the ReadArgs call.  It is a publicly defined structure
  8.  * which may be used by applications which use code that follows the
  9.  * conventions defined for access.
  10.  *
  11.  * When passed to the dos.library functions, the value passed as
  12.  * struct *CSource is defined as follows:
  13.  *      if ( CSource == 0)      Use buffered IO "ReadChar()" as data source
  14.  *      else                    Use CSource for input character stream
  15.  *
  16.  * The following two pseudo-code routines define how the CSource structure
  17.  * is used:
  18.  *
  19.  * long CS_ReadChar( struct CSource *CSource )
  20.  *
  21.  *      if ( CSource == 0 )     return ReadChar();
  22.  *      if ( CSource->CurChr >= CSource->Length )       return ENDSTREAMCHAR;
  23.  *      return CSource->Buffer[ CSource->CurChr++ ];
  24.  *
  25.  *
  26.  * BOOL CS_UnReadChar( struct CSource *CSource )
  27.  *
  28.  *      if ( CSource == 0 )     return UnReadChar();
  29.  *      if ( CSource->CurChr <= 0 )     return FALSE;
  30.  *      CSource->CurChr--;
  31.  *      return TRUE;
  32.  *
  33.  *
  34.  * To initialize a struct CSource, you set CSource->CS_Buffer to
  35.  * a string which is used as the data source, and set CS_Length to
  36.  * the number of characters in the string.  Normally CS_CurChr should
  37.  * be initialized to ZERO, or left as it was from prior use as
  38.  * a CSource.
  39.  *
  40.  *********************************************************************}
  41.  
  42. Type
  43.        CSource = Record
  44.         CS_Buffer  : String;
  45.         CS_Length,
  46.         CS_CurChr  : Integer;
  47.        END;
  48.        CSourcePtr = ^CSource;
  49.  
  50. {   *********************************************************************
  51.  *
  52.  * The RDArgs data structure is the input parameter passed to the DOS
  53.  * ReadArgs() function call.
  54.  *
  55.  * The RDA_Source structure is a CSource as defined above;
  56.  * if RDA_Source.CS_Buffer is non-null, RDA_Source is used as the input
  57.  * character stream to parse, else the input comes from the buffered STDIN
  58.  * calls ReadChar/UnReadChar.
  59.  *
  60.  * RDA_DAList is a private address which is used internally to track
  61.  * allocations which are freed by FreeArgs().  This MUST be initialized
  62.  * to NULL prior to the first call to ReadArgs().
  63.  *
  64.  * The RDA_Buffer and RDA_BufSiz fields allow the application to supply
  65.  * a fixed-size buffer in which to store the parsed data.  This allows
  66.  * the application to pre-allocate a buffer rather than requiring buffer
  67.  * space to be allocated.  If either RDA_Buffer or RDA_BufSiz is NULL,
  68.  * the application has not supplied a buffer.
  69.  *
  70.  * RDA_ExtHelp is a text string which will be displayed instead of the
  71.  * template string, if the user is prompted for input.
  72.  *
  73.  * RDA_Flags bits control how ReadArgs() works.  The flag bits are
  74.  * defined below.  Defaults are initialized to ZERO.
  75.  *
  76.  *********************************************************************}
  77.  
  78.        RDArgs = Record
  79.         RDA_Source  : CSource;     {    Select input source }
  80.         RDA_DAList  : Integer;             {    PRIVATE. }
  81.         RDA_Buffer  : String;            {    Optional string parsing space. }
  82.         RDA_BufSiz  : Integer;             {    Size of RDA_Buffer (0..n) }
  83.         RDA_ExtHelp : String;           {    Optional extended help }
  84.         RDA_Flags   : Integer;              {    Flags for any required control }
  85.        END;
  86.        RDArgsPtr = ^RDArgs;
  87.  
  88. CONST
  89.        RDAB_STDIN     = 0;       {    Use "STDIN" rather than "COMMAND LINE" }
  90.        RDAF_STDIN     = 1;
  91.        RDAB_NOALLOC   = 1;       {    If set, do not allocate extra string space.}
  92.        RDAF_NOALLOC   = 2;
  93.        RDAB_NOPROMPT  = 2;       {    Disable reprompting for string input. }
  94.        RDAF_NOPROMPT  = 4;
  95.  
  96. {   *********************************************************************
  97.  * Maximum number of template keywords which can be in a template passed
  98.  * to ReadArgs(). IMPLEMENTOR NOTE - must be a multiple of 4.
  99.  *********************************************************************}
  100.        MAX_TEMPLATE_ITEMS     = 100;
  101.  
  102. {   *********************************************************************
  103.  * Maximum number of MULTIARG items returned by ReadArgs(), before
  104.  * an ERROR_LINE_TOO_LONG.  These two limitations are due to stack
  105.  * usage.  Applications should allow "a lot" of stack to use ReadArgs().
  106.  *********************************************************************}
  107.        MAX_MULTIARGS          = 128;
  108.  
  109.  
  110. FUNCTION FindArgs(Template, KeyWord : String) : Integer;
  111.     External;
  112.  
  113. PROCEDURE FreeArgs(Args : RDArgsPtr);
  114.     External;
  115.  
  116. FUNCTION ReadArgs(template : String; Buffer : Address; RD : RDArgsPtr) : RDArgsPtr;
  117.     External;
  118.  
  119. FUNCTION ReadItem(buffer : String; BufferSize : Integer; CS : CSourcePtr) : Integer;
  120.     External;
  121.  
  122.